#define _CRT_SECURE_NO_WARNINGS
/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};*/
class PalindromeList {
    ListNode* mid(ListNode* head)
    {
        ListNode* slow, * fast;
        slow = fast = head;
        while (fast && fast->next)
        {
            slow = slow->next;
            fast = fast->next->next;
        }
        return slow;

    }
    ListNode* reverse(ListNode* head)
    {
        ListNode* n1, * n2, * n3;
        n1 = NULL;
        n2 = head;
        n3 = n2->next;
        while (n2)
        {
            n2->next = n1;
            n1 = n2;
            n2 = n3;
            if (n3)
            {
                n3 = n3->next;
            }
        }
        return n1;
    }
public:
    bool chkPalindrome(ListNode* A) {
        ListNode* midde = mid(A);
        ListNode* ret = reverse(midde);
        ListNode* pcur = A;
        while (ret)
        {
            if (ret->val != pcur->val)
            {
                return false;
            }
            ret = ret->next;
            pcur = pcur->next;
        }
        return true;
    }
};